package com.suse.lhw.tools;

import com.suse.lhw.domin.PHealthData;
import com.suse.lhw.domin.PIfo;
import org.springframework.http.ZeroCopyHttpOutputMessage;

import java.text.SimpleDateFormat;

/**
 * @ProjectName: health_manage_system
 * @Package: com.suse.lhw.tools
 * @ClassName: CaloriesCalculate
 * @Description: java类作用描述
 * @Author: 李鸿炜
 * @CreateDate: 2020/5/21 21:50
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/5/21 21:50
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class CaloriesCalculate {
    public static int dailyBasicCosumed(PHealthData pHealthData, PIfo pIfo) {
        //通过健康信息算出每日不运动的基本消耗
//        女: BMR = 655 + (9.6 x 体重 kg) + ( 1.8 x 身高 cm ) - ( 4.7 x 年龄 years )
//        男: BMR = 66 + (13.7 x 体重 kg) + ( 5 x 身高 cm ) - ( 6.8 x 年龄 years )
        if (pIfo.getSex().equals("男")) {
            return (int) (66 + (13.7 * pHealthData.getNewWeight() + 5 * pHealthData.getLength() - (4.7 * pHealthData.getAge())));
        } else
            return (int) (655 + (9.6 * pHealthData.getNewWeight() + 5 * pHealthData.getLength() - (6.8 * pHealthData.getAge())));
    }

    public static int couldEat(int dailyBasicCosumed, PHealthData pHealthData, int movementCosume, int ateCalories) {
        /**
         * @Author:Hongwei Li
         * @Description:
         *            吃-消耗=规定差
         *            （还能吃+已经吃）-（运动消耗+基本消耗）=规定差
         *            还能吃=规定差+运动消耗+基本消耗-已经吃
         *
         *
         * @Date:23:04 2020/5/21
         * @Param:[dailyBasicCosumed, pHealthData, movementCosume, ateCalories]
         * @Return:int
         **/
        //计算规定差，规定差是通过data中的现体重，预期体重，需要的时间算出每天需要产生的消耗和摄入差
        //热量和体重转化公式： 营养学通常计算 7700 千卡消耗一公斤脂肪
        int regular = (int)
                ((pHealthData.getNewWeight() - pHealthData.getTargetWeight())
                        / ((pHealthData.getEndtime().getTime() - pHealthData.getStarttime().getTime()) / (24 * 60 * 60 * 1000))
                        / 7700);
        // 还能吃=规定差+运动消耗+基本消耗-已经吃
        return regular + movementCosume + dailyBasicCosumed - ateCalories;
    }

    public static int getRegular(int dailyBasicCosumed, PHealthData pHealthData, int movementCosume, int ateCalories) {
        /**
         * @Author:Hongwei Li
         * @Description:
         *            吃-消耗=规定差
         *            （还能吃+已经吃）-（运动消耗+基本消耗）=规定差
         *            还能吃=规定差+运动消耗+基本消耗-已经吃
         * @Date:23:04 2020/5/21
         * @Param:[dailyBasicCosumed, pHealthData, movementCosume, ateCalories]
         * @Return:int
         **/
        //计算规定差，规定差是通过data中的现体重，预期体重，需要的时间算出每天需要产生的消耗和摄入差
        //热量和体重转化公式： 营养学通常计算 7700 千卡消耗一公斤脂肪
        int regular = (int)
                ((pHealthData.getNewWeight() - pHealthData.getTargetWeight())
                        / ((pHealthData.getEndtime().getTime() - pHealthData.getStarttime().getTime()) / (24 * 60 * 60 * 1000))
                        / 7700);
        // 还能吃=规定差+运动消耗+基本消耗-已经吃
        return regular;
    }
}
